package com.jianguozh.difs.common.utils;

import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * Lambda工具类
 *
 * @author hanrs
 * @email 4076130@qq.com
 * @since 2022/4/2 9:07
 */
public class LambdaUtils {

    /**
     * 拓展for each中无index
     *
     * @param consumer
     * @param <T>
     * @return
     */
    public static <T> Consumer<T> consumerWithIndex(BiConsumer<T, Integer> consumer) {
        class Obj {
            int i;
        }
        Obj obj = new Obj();
        return t -> {
            int index = obj.i++;
            consumer.accept(t, index);
        };
    }
}

